package com.uedu.manager;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.uedu.util.ConnectionFactory;
import com.uedu.util.DataRelease;
import com.uedu.vo.Student;

public class StudentManager {

	public boolean login(Student student){

		boolean flag = false ;
		
		Connection conn = ConnectionFactory.getConnection() ;

		Statement stmt = null ;

		ResultSet rs = null ;

		try {

			stmt = conn.createStatement();
			
			String number = student.getStu_number();
			String passwd = student.getStu_passwd();

			rs = stmt.executeQuery("select * from student where stu_number ='"+number+"' and stu_passwd = '"+passwd+"'");

			if(rs.next()){
				
				student.setStu_sex(rs.getString("stu_sex"));
				student.setStu_name(rs.getString("stu_name"));
				
				flag = true ;
			}


		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DataRelease.Release(rs, stmt, conn);
		}

		return flag ;
	}
	
	public boolean regist(String stu_name,String stu_number, String stu_passwd,String stu_sex){
		
		boolean flag = false ;
		
		Connection conn= ConnectionFactory.getConnection();
		Statement stmt = null ;
		ResultSet rs = null ;
		String sql ;
		try {

			stmt = conn.createStatement();
			sql = "insert into student (id, stu_number,stu_name, stu_sex, stu_passwd)"+
			" values ('6', '"+stu_number+"',  '"+stu_name+"',  '"+stu_sex+"',  '"+stu_passwd+"')" ;
			
			stmt.executeUpdate(sql);
			
			flag = true ;

		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DataRelease.Release(rs, stmt, conn);
		}
		
		return flag ;

		
	}

}
